package cn.agiledata.bank.common.tag;

import javax.servlet.jsp.JspException;

import org.apache.struts.taglib.TagUtils;
import org.apache.struts.taglib.bean.WriteTag;

import cn.agiledata.bank.common.util.ConvertUtil;

public class PasswordStrengthTag extends WriteTag{
	private String objectName;
	private String width;
	private String height;
	private String minLength;
	
	public PasswordStrengthTag() {
		super();
		this.width="200";
		this.height="20";
		this.minLength="6";			
	}

	public String getObjectName() {
		return objectName;
	}

	public void setObjectName(String objectName) {
		this.objectName = objectName;
	}
	

    public String getHeight() {
		return height;
	}

	public void setHeight(String height) {
		this.height = height;
	}

	public String getMinLength() {
		return minLength;
	}

	public void setMinLength(String minLength) {
		this.minLength = minLength;
	}

	public String getWidth() {
		return width;
	}

	public void setWidth(String width) {
		this.width = width;
	}

	/**
     * Generate the required input tag.
     * <p>
     * Support for indexed property since Struts 1.1
     *
     * @exception JspException if a JSP exception has occurred
     */
    public int doStartTag() throws JspException {
    	
        //图片
        TagUtils.getInstance().write(this.pageContext, this.renderPasswordStrength());
        // Continue processing this page
        return (SKIP_BODY);		

    }	
    
    /**
     * 构造密码强度
     * @return
     */
    public String renderPasswordStrength() {
    	StringBuffer sb = new StringBuffer();
    	sb.append("密码检测：")
    	  .append("<script language='javascript'>")
    	  .append(" var ")
    	  .append(getObjectName())
    	  .append(" = new PasswordStrength(); ")
    	  .append(getObjectName())
    	  .append(".setSize('")
    	  .append(getWidth())
    	  .append("','")
    	  .append(getHeight())
    	  .append("');")
    	  .append(getObjectName())
    	  .append(".setMinLength(")
    	  .append(getMinLength())
    	  .append(");")
    	  .append("</script>");
    	return sb.toString();
    }
}
